home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Util / L / Locare 1.9 SW.cpt / Locare 1.9 SW / TEXT Hook.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-07-26  |  2.6 KB  |  99 lines  |  [TEXT/KAHL]

  1. /*    TEXT Hook.c is a rather cheap, nevertheless illustrative, example of
  2.     a Preview hook for Locare 1.9 or above.  This hook is enabled for
  3.     files of type TEXT.  It just reads the first 2000 (or less if the
  4.     file is shorter) characters of a matched file and displays as much
  5.     as it can in a window.  The user clicks to exit the preview hook.
  6.     
  7.     
  8.     Written in LightspeedC from THINK Technologies, Inc.
  9.     
  10.     
  11.     Feel free to use this as an example or a foundation for your own
  12.     endeavors.  If you wish to improve upon this, go right ahead.
  13.     
  14.     NOTE: This hook is messy.  It is meant to serve as an example.
  15.     It is functional as is, but it could be much better…  More defenses
  16.     could be used.
  17. */
  18.  
  19.  
  20.  
  21.  
  22. #include <EventMgr.h>
  23. #include <MacTypes.h>
  24. #include <FileMgr.h>
  25. #include <FontMgr.h>
  26. #include <WindowMgr.h>
  27.  
  28. typedef struct
  29. {    char        version;    /* 1 for now */
  30.     char        message;
  31.     int            volume;
  32.     long        directory;
  33.     int            index;
  34. }    PreviewRec;
  35.  
  36.  
  37. pascal void main(infoPtr)
  38. PreviewRec *infoPtr;
  39. {    char nameString[256];
  40.     ParamBlockRec myHRec;
  41.     WindowPtr myWin;
  42.     Rect rect;
  43.     char Buffer[2000];        /* 2000 byte buffer */
  44.     
  45.     myHRec.fileParam.ioFDirIndex = infoPtr->index;
  46.     myHRec.fileParam.ioFlNum = infoPtr->directory;
  47.     myHRec.fileParam.ioVRefNum = infoPtr->volume;
  48.     myHRec.fileParam.ioNamePtr = (StringPtr)nameString;
  49.     PBGetCatInfo(&myHRec,FALSE);
  50.  
  51.     myHRec.fileParam.ioFlNum = infoPtr->directory;
  52.     myHRec.fileParam.ioVRefNum = infoPtr->volume;
  53.     myHRec.fileParam.ioNamePtr = (StringPtr)nameString;
  54.     myHRec.fileParam.filler1 = fsRdPerm;    /* LS C's file mgr header
  55.             doesn't offer much support for H Rec's....ioParam offers none.
  56.             I have modified my own header to include H rec's, but maybe
  57.             you haven't.  So I just used the available fileParam, where
  58.             filler1 = ioPermssn byte. */
  59.     myHRec.fileParam.ioFDirIndex = 0;
  60.     PBHOpen(&myHRec,FALSE);
  61.     rect.top = 41;
  62.     rect.left = 11;
  63.     rect.right = rect.left + 490;
  64.     rect.bottom = rect.top + 300;
  65.     
  66.     myWin = NewWindow(0L,&rect,nameString,TRUE,noGrowDocProc,-1L,FALSE,0L);
  67.     SetPort(myWin);
  68.     
  69.     myHRec.ioParam.ioPosMode = fsFromStart;
  70.     myHRec.ioParam.ioBuffer = Buffer;
  71.     myHRec.ioParam.ioPosOffset = 0;
  72.     myHRec.ioParam.ioReqCount = 2000;
  73.     PBRead(&myHRec,FALSE);
  74.     
  75.     TextSize(9);
  76.     TextFont(monaco);
  77.     rect.top = 1;
  78.     rect.left = 2;
  79.     rect.right = rect.left + 488;
  80.     rect.bottom = rect.top + 285;
  81.     TextBox(Buffer,myHRec.ioParam.ioActCount,&rect,0);
  82.     MoveTo(0,286);
  83.     LineTo(490,286);
  84.     
  85.     MoveTo(5,298);
  86.     DrawString("\p'TEXT' file preview hook by Raymond Lau.  \
  87. Please <CLICK> to continue…");
  88.     do
  89.     {}
  90.     while(!Button());
  91.     FlushEvents(mDownMask,0l);
  92.     
  93.     DisposeWindow(myWin);
  94.     
  95.     
  96.     PBClose(&myHRec,FALSE);
  97.     infoPtr->message = 1;
  98.     return;
  99. }